import request from '@/utils/http'
import type { BaseEntity } from './gen_business'

export interface GenColumn extends BaseEntity {
  name: string
  comment: string
  type: string
  pd_type: string
  default: string
  sort: number
  length: number
  is_pk: boolean
  is_nullable: boolean
  gen_business_id: number
}

// 创建请求体
export interface GenColumnCreate extends Omit<GenColumn, keyof BaseEntity> { }

// 更新请求体
export interface GenColumnUpdate extends Partial<GenColumnCreate> { }

/**
 * @description 获取指定业务的所有代码生成列
 * @param business_id
 */
export function fetchGenColumnList(business_id: number) {
  return request.get<GenColumn[]>({
    url: `/code-generator/columns/list/${business_id}`
  })
}

/**
 * @description 创建新的代码生成列
 * @param data
 */
export function createGenColumn(data: GenColumnCreate) {
  return request.post<GenColumn>({
    url: '/code-generator/columns/create',
    data,
    showSuccessMessage: true
  })
}

/**
 * @description 更新代码生成列
 * @param id
 * @param data
 */
export function updateGenColumn(id: number, data: GenColumnUpdate) {
  return request.put<GenColumn>({
    url: `/code-generator/columns/update/${id}`,
    data,
    showSuccessMessage: true
  })
}

/**
 * @description 删除代码生成列
 * @param id
 */
export function deleteGenColumn(id: number) {
  return request.del<null>({
    url: `/code-generator/columns/delete/${id}`,
    showSuccessMessage: true
  })
}